package models

import (
	"OnlineRetailers/models/Admin"
	USER "OnlineRetailers/models/User"
	"OnlineRetailers/models/express"
	"fmt"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	// set default database
	err := orm.RegisterDataBase("default", "mysql", "root:root@gjh_200914@tcp(42.194.131.65:13306)/OnlineRetailers?charset=utf8") //public123456
	//err := orm.RegisterDataBase("default", "mysql", "root:public123456@tcp(127.0.0.1:3306)/OnlineRetailers?charset=utf8") //public123456
	if err != nil {
		fmt.Println(err)
	}
	// register model
	orm.RegisterModel(new(Admin.User), new(Admin.Coupon), new(Admin.ProductDetailed), new(Admin.Activity),
		new(Admin.Classification), new(Admin.IMG), new(USER.Order), new(USER.Address),
		new(USER.Score), new(USER.WXUser), new(USER.ShoppingCart), new(USER.OrderCart),
		new(Admin.Freight), new(Admin.SmallClass), new(express.ExpressId),
	)

	// create table
	err = orm.RunSyncdb("default", false, true)
	if err != nil {
		fmt.Println(err)
	}
}
